package com.xvyy.tingshu.account.service.impl;

import com.xvyy.tingshu.account.mapper.RechargeInfoMapper;
import com.xvyy.tingshu.account.service.RechargeInfoService;
import com.xvyy.tingshu.common.constant.SystemConstant;
import com.xvyy.tingshu.model.account.RechargeInfo;
import com.xvyy.tingshu.vo.account.RechargeInfoVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class RechargeInfoServiceImpl extends ServiceImpl<RechargeInfoMapper, RechargeInfo> implements RechargeInfoService {

	@Autowired
	private RechargeInfoMapper rechargeInfoMapper;

    @Override
    public Map<String, String> submitRecharge(RechargeInfoVo rechargeInfoVo, Long userId) {
        RechargeInfo rechargeInfo = new RechargeInfo();
        rechargeInfo.setUserId(userId);
        rechargeInfo.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
        rechargeInfo.setRechargeStatus(SystemConstant.ORDER_STATUS_UNPAID);
        rechargeInfo.setRechargeAmount(rechargeInfoVo.getAmount());
        rechargeInfo.setPayWay(rechargeInfoVo.getPayWay());
        rechargeInfoMapper.insert(rechargeInfo);
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("orderNo", rechargeInfo.getOrderNo());
        return resultMap;
    }
}
